Conversation
This commit migrates the aloha package's service layer from Tornado + requests to FastAPI + httpx for better async support and modern web framework. Key changes: - Replaced Tornado web.Application with FastAPI - Replaced requests library with httpx for HTTP client operations - Updated base_api_handler.py for FastAPI request handling - Updated base_api_client.py to use httpx.AsyncClient - Updated files.py to use httpx for file downloads - Updated API v0, v1, v2 modules to work with FastAPI - Updated app.py to use uvicorn for running the service - Updated web.py to register routes from handler classes - Maintained backward compatibility for existing handler class patterns - Updated src example code (api_common_sys_info.py) to work with new framework The src/example programs should work with minimal changes, mainly ensuring the service modules are registered in the configuration.
|
|
- Removed tornado and requests from service dependencies in setup.py - Added uvicorn to service dependencies (required for running FastAPI) - Updated src/requirements.txt to match the new dependencies
…eption'' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Bibo Hao <haobibo@users.noreply.github.com>
| content = data | ||
| else: | ||
| content = json.dumps(data, ensure_ascii=False, default=str, separators=(",", ":")) | ||
| return Response(content=content, status_code=status_code, media_type="application/json") |
| except Exception as e: | ||
| handler.LOG.error(e, exc_info=True) | ||
| msgs = ["An internal error has occurred.", str(e)] | ||
| return JSONResponse({"status": "error", "message": msgs}, status_code=500) |
| } | ||
| LOG.debug(_config) | ||
| msg = {k: ("***" if k == "password" else v) for k, v in _config.items()} | ||
| LOG.debug(msg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the aloha package's service layer from Tornado + requests to FastAPI + httpx for better async support and modern web framework.
Key Changes
web.pyandapp.pymodules now use FastAPI instead of Tornado for the web application frameworkbase_api_handler.pyupdated for FastAPI request handlingbase_api_client.pynow useshttpx.AsyncClientwith proper retry supportfiles.pyuses httpx for file downloadsBackward Compatibility
The changes maintain backward compatibility for existing handler class patterns. The src/example programs should work with minimal changes - mainly ensuring service modules are registered in the configuration.
Dependencies
The
setup.pyalready includes fastapi and httpx in the service dependencies:Testing
The service was tested with:
curl http://localhost:8888/api/common/sys_infocurl http://localhost:8888/api/common/sys_info?kind=cpucurl http://localhost:8888/api/common/sys_info/cpuAll tests passed successfully.
@haobibo can click here to continue refining the PR